﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:NJL_SYS_CS_CONTACT_TYPE
	/// </summary>
	public partial class NJL_SYS_CS_CONTACT_TYPE:INJL_SYS_CS_CONTACT_TYPE
	{
		public NJL_SYS_CS_CONTACT_TYPE()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string TYPE_CODE)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NJL_SYS_CS_CONTACT_TYPE");
			strSql.Append(" where TYPE_CODE=@TYPE_CODE ");
			SqlParameter[] parameters = {
					new SqlParameter("@TYPE_CODE", SqlDbType.VarChar,20)};
			parameters[0].Value = TYPE_CODE;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_SYS_CS_CONTACT_TYPE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NJL_SYS_CS_CONTACT_TYPE(");
			strSql.Append("TYPE_CODE,TYPE_NAME)");
			strSql.Append(" values (");
			strSql.Append("@TYPE_CODE,@TYPE_NAME)");
			SqlParameter[] parameters = {
					new SqlParameter("@TYPE_CODE", SqlDbType.VarChar,20),
					new SqlParameter("@TYPE_NAME", SqlDbType.VarChar,50)};
			parameters[0].Value = model.TYPE_CODE;
			parameters[1].Value = model.TYPE_NAME;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_SYS_CS_CONTACT_TYPE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NJL_SYS_CS_CONTACT_TYPE set ");
			strSql.Append("TYPE_NAME=@TYPE_NAME");
			strSql.Append(" where TYPE_CODE=@TYPE_CODE ");
			SqlParameter[] parameters = {
					new SqlParameter("@TYPE_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@TYPE_CODE", SqlDbType.VarChar,20)};
			parameters[0].Value = model.TYPE_NAME;
			parameters[1].Value = model.TYPE_CODE;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string TYPE_CODE)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_SYS_CS_CONTACT_TYPE ");
			strSql.Append(" where TYPE_CODE=@TYPE_CODE ");
			SqlParameter[] parameters = {
					new SqlParameter("@TYPE_CODE", SqlDbType.VarChar,20)};
			parameters[0].Value = TYPE_CODE;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string TYPE_CODElist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_SYS_CS_CONTACT_TYPE ");
			strSql.Append(" where TYPE_CODE in ("+TYPE_CODElist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_SYS_CS_CONTACT_TYPE GetModel(string TYPE_CODE)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 TYPE_CODE,TYPE_NAME from NJL_SYS_CS_CONTACT_TYPE ");
			strSql.Append(" where TYPE_CODE=@TYPE_CODE ");
			SqlParameter[] parameters = {
					new SqlParameter("@TYPE_CODE", SqlDbType.VarChar,20)};
			parameters[0].Value = TYPE_CODE;

			NJL.Model.NJL_SYS_CS_CONTACT_TYPE model=new NJL.Model.NJL_SYS_CS_CONTACT_TYPE();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["TYPE_CODE"]!=null && ds.Tables[0].Rows[0]["TYPE_CODE"].ToString()!="")
				{
					model.TYPE_CODE=ds.Tables[0].Rows[0]["TYPE_CODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TYPE_NAME"]!=null && ds.Tables[0].Rows[0]["TYPE_NAME"].ToString()!="")
				{
					model.TYPE_NAME=ds.Tables[0].Rows[0]["TYPE_NAME"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TYPE_CODE,TYPE_NAME ");
			strSql.Append(" FROM NJL_SYS_CS_CONTACT_TYPE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" TYPE_CODE,TYPE_NAME ");
			strSql.Append(" FROM NJL_SYS_CS_CONTACT_TYPE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "NJL_SYS_CS_CONTACT_TYPE";
			parameters[1].Value = "TYPE_CODE";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

